package com.ufaud.ais.sys.service;

import com.ufaud.ais.pub.dao.IGenericCRUDDao;
import com.ufaud.ais.sys.entity.CustomItem;
import com.ufaud.ais.sys.entity.CustomItemType;
import com.ufaud.ais.sys.entity.Department;
import com.ufaud.ais.sys.entity.Employee;
import com.ufaud.ais.sys.entity.MenuItem;
import com.ufaud.ais.sys.entity.Role;

public class InitDataServiceImpl implements InitDataService {

	IGenericCRUDDao<Role, Long> roleDao;
	IGenericCRUDDao<Department, Long> deptDao;
	IGenericCRUDDao<Employee, Long> empDao;
	IGenericCRUDDao<CustomItemType, Long> itemDao;
	IGenericCRUDDao<MenuItem, Long> menuItemDao;

	public InitDataServiceImpl(IGenericCRUDDao<Role, Long> roleDao, IGenericCRUDDao<Department, Long> deptDao, IGenericCRUDDao<Employee, Long> empDao, IGenericCRUDDao<CustomItemType, Long> itemDao, IGenericCRUDDao<MenuItem, Long> menuItemDao) {
		this.roleDao = roleDao;
		this.deptDao = deptDao;
		this.empDao = empDao;
		this.itemDao = itemDao;
		this.menuItemDao = menuItemDao;
	}

	public void initData() {
		Role roleHR = new Role();
		roleHR.setRoleName("人力资源管理员");
		roleHR.setRoleCode("ROLE_HR");

		Role roleManager = new Role();
		roleManager.setRoleName("部门经理");
		roleManager.setRoleCode("ROLE_MANAGER");

		Role roleEmployee = new Role();
		roleEmployee.setRoleName("用户");
		roleEmployee.setRoleCode("ROLE_EMPLOYEE");

		Role roleDeveloper = new Role();
		roleDeveloper.setRoleName("开发人员");
		roleDeveloper.setRoleCode("ROLE_DEVELOPER");

		roleDao.save(roleHR);
		roleDao.save(roleManager);
		roleDao.save(roleEmployee);
		roleDao.save(roleDeveloper);

		// Session session =
		// roleDao.getHibernateTemplate().getSessionFactory(). openSession();
		// Transaction tx = session.beginTransaction();
		Department dev = new Department();
		dev.setDeptName("研发中心");
		deptDao.save(dev);

		Department productPlan = new Department();
		productPlan.setDeptName("产品规划部");

		Department shenyi = new Department();
		shenyi.setDeptName("审易研发部");

		Department java = new Department();
		java.setDeptName("Java研发部");

		Department java_productdemand = new Department();
		java_productdemand.setDeptName("产品需求");

		Department java_lw = new Department();
		java_lw.setDeptName("联网产品");
		java_lw.setDeptDesc("1\\在线作业+监控预警系统设计、实现\n2\\税务行业版设计实现\n3\\项目二次开发\n4\\产品手册编写\n5\\原形项目售前实施支持\n6\\二次开发项目合同审定6\\发版通知(含功能列表)");

		Department java_gl = new Department();
		java_gl.setDeptName("管理产品");
		java_gl.setDeptDesc("1\\管理系统设计、实现\n2\\项目二次开发\n3\\产品手册编写\n4\\二次开发项目合同审定\n5\\原形项目售前实施支持\n6\\发版通知(含功能列表)");

		Department java_invest = new Department();
		java_invest.setDeptName("投资产品");
		java_invest.setDeptDesc("1\\投资审计系统设计、实现\n1\\产品规划、需求、设计、实现\n2\\项目二次开发\n3\\产品手册编写\n4\\原形项目售前实施支持\n5\\二次开发项目合同审定\n6\\发版通知(含功能列表)");

		java.addSubDepartment(java_lw);
		java.addSubDepartment(java_gl);
		java.addSubDepartment(java_productdemand);
		java.addSubDepartment(java_invest);

		dev.addSubDepartment(productPlan);
		dev.addSubDepartment(shenyi);
		dev.addSubDepartment(java);

		Employee lmk = new Employee();
		lmk.setEmail("linke@ufaud.com");
		lmk.setEmployeeName("林可");
		lmk.setAccountName("linke");
		lmk.setAccountPassword("1234");
		lmk.setJob("研发工程师");
		lmk.setEmployeeCode("0000148");
		lmk.setDepartment(java_lw);
		lmk.addRole(roleEmployee);
		lmk.addRole(roleDeveloper);
		// lmk.addRole(roleManager);
		empDao.save(lmk);

		Employee mouDun = new Employee();
		mouDun.setEmail("chenjd@ufaud.com");
		mouDun.setEmployeeName("陈佳敦");
		mouDun.setAccountName("chenjd");
		mouDun.setAccountPassword("1234");
		mouDun.setJob("研发工程师");
		mouDun.setEmployeeCode("0000153");
		mouDun.setDepartment(java_lw);
		mouDun.addRole(roleEmployee);
		mouDun.addRole(roleDeveloper);
		empDao.save(mouDun);

		Employee chenShaobing = new Employee();
		chenShaobing.setEmail("chensb@ufaud.com");
		chenShaobing.setEmployeeName("陈绍彬");
		chenShaobing.setAccountName("chensb");
		chenShaobing.setAccountPassword("1234");
		chenShaobing.setJob("技术总监");
		chenShaobing.setEmployeeCode("13581544629");
		chenShaobing.setDepartment(dev);
		chenShaobing.addRole(roleManager);
		chenShaobing.addRole(roleEmployee);
		empDao.save(chenShaobing);
		dev.setDeptManager(chenShaobing);

		Employee wangxing = new Employee();
		wangxing.setEmail("wangxing@ufaud.com");
		wangxing.setEmployeeName("王星");
		wangxing.setAccountName("wangxing");
		wangxing.setAccountPassword("1234");
		wangxing.setJob("部门经理");
		wangxing.setEmployeeCode("13910283186");
		wangxing.setDepartment(productPlan);
		wangxing.addRole(roleManager);
		wangxing.addRole(roleEmployee);
		empDao.save(wangxing);
		productPlan.setDeptManager(wangxing);

		Employee caohongliang = new Employee();
		caohongliang.setEmail("caohl@ufaud.com");
		caohongliang.setEmployeeName("曹洪亮");
		caohongliang.setAccountName("chaohl");
		caohongliang.setAccountPassword("1234");
		caohongliang.setJob("部门经理");
		caohongliang.setEmployeeCode("13439213447");
		caohongliang.setDepartment(shenyi);
		caohongliang.addRole(roleManager);
		caohongliang.addRole(roleEmployee);
		empDao.save(caohongliang);
		shenyi.setDeptManager(caohongliang);

		Employee lihao = new Employee();
		lihao.setEmail("lihao@ufaud.com");
		lihao.setEmployeeName("李浩");
		lihao.setAccountName("lihao");
		lihao.setAccountPassword("1234");
		lihao.setJob("部门经理");
		lihao.setEmployeeCode("13781978818");
		lihao.setDepartment(java);
		lihao.addRole(roleManager);
		lihao.addRole(roleEmployee);
		empDao.save(lihao);
		java.setDeptManager(lihao);

		Employee tianyq = new Employee();
		tianyq.setEmail("tianyq@ufaud.com");
		tianyq.setEmployeeName("田运全");
		tianyq.setAccountName("tianyq");
		tianyq.setAccountPassword("1234");
		tianyq.setJob("产品经理");
		tianyq.setEmployeeCode("13426431880");
		tianyq.setDepartment(java_productdemand);
		tianyq.addRole(roleManager);
		tianyq.addRole(roleEmployee);
		empDao.save(tianyq);
		java_productdemand.setDeptManager(tianyq);

		Employee gubiao = new Employee();
		gubiao.setEmail("gubiao@ufaud.com");
		gubiao.setEmployeeName("谷彪");
		gubiao.setAccountName("gubiao");
		gubiao.setAccountPassword("1234");
		gubiao.setJob("管理产品开发经理");
		gubiao.setEmployeeCode("13264200389");
		gubiao.setDepartment(java_gl);
		gubiao.addRole(roleManager);
		gubiao.addRole(roleEmployee);
		empDao.save(gubiao);
		java_gl.setDeptManager(gubiao);

		Employee zhangzz = new Employee();
		zhangzz.setEmail("zhangzz@ufaud.com");
		zhangzz.setEmployeeName("张治志");
		zhangzz.setAccountName("zhangzz");
		zhangzz.setAccountPassword("1234");
		zhangzz.setJob("联网产品开发经理");
		zhangzz.setEmployeeCode("15810233495");
		zhangzz.setDepartment(java_lw);
		zhangzz.addRole(roleManager);
		zhangzz.addRole(roleEmployee);
		empDao.save(zhangzz);
		java_lw.setDeptManager(zhangzz);

		Employee wangly = new Employee();
		wangly.setEmail("wangly@ufaud.com");
		wangly.setEmployeeName("王立业");
		wangly.setAccountName("wangly");
		wangly.setAccountPassword("1234");
		wangly.setJob("投资产品开发经理");
		wangly.setEmployeeCode("13269051101");
		wangly.setDepartment(java_invest);
		wangly.addRole(roleManager);
		wangly.addRole(roleEmployee);
		empDao.save(wangly);
		java_invest.setDeptManager(wangly);
		
		CustomItemType position = new CustomItemType();
		position.setItemTypeName("岗位");
		position.setItemTypeDesc("岗位信息入口");
		itemDao.save(position);
		
		CustomItem developer = new CustomItem();
		developer.setItemName("研发工程师");
		developer.setItemDesc("嘿嘿，传说中的软件民工是也");
		position.addCustomItem(developer);
		
		CustomItem test = new CustomItem();
		test.setItemName("测试工程师");
		test.setItemDesc("What does BDD mean? -- Bug驱动开发");
		position.addCustomItem(test);
		
		CustomItem deptMng = new CustomItem();
		deptMng.setItemName("部门经理");
		deptMng.setItemDesc("分舵主");
		position.addCustomItem(deptMng);
		
		MenuItem sysAdmin = new MenuItem();
		sysAdmin.setMenuItemName("系统管理");
		sysAdmin.setMenuItemType(MenuItem.TYPE_DIR);
		sysAdmin.setMenuItemLevel(0);
		menuItemDao.save(sysAdmin);

		MenuItem attendance = new MenuItem();
		attendance.setMenuItemName("考勤");
		attendance.setMenuItemType(MenuItem.TYPE_DIR);
		attendance.setMenuItemLevel(0);
		menuItemDao.save(attendance);

		MenuItem analyseQuery = new MenuItem();
		analyseQuery.setMenuItemName("分析查询");
		analyseQuery.setMenuItemType(MenuItem.TYPE_DIR);
		analyseQuery.setMenuItemLevel(0);
		menuItemDao.save(analyseQuery);
		
		MenuItem sysAdmin_1 = new MenuItem();
		sysAdmin_1.setMenuItemName("人员管理");
		sysAdmin_1.setMenuItemTarget("/sys/employee/tolist.action");
		sysAdmin_1.setMenuItemType(MenuItem.TYPE_URL);
		sysAdmin_1.setMenuItemLevel(1);
		sysAdmin.addMenuItem(sysAdmin_1);
		
		MenuItem sysAdmin_2 = new MenuItem();
		sysAdmin_2.setMenuItemName("部门管理");
		sysAdmin_2.setMenuItemTarget("/sys/dept/toPage/main.action");
		sysAdmin_2.setMenuItemType(MenuItem.TYPE_URL);
		sysAdmin_2.setMenuItemLevel(1);
		sysAdmin.addMenuItem(sysAdmin_2);
		
		MenuItem sysAdmin_3 = new MenuItem();
		sysAdmin_3.setMenuItemName("角色管理");
		sysAdmin_3.setMenuItemTarget("#");
		sysAdmin_3.setMenuItemType(MenuItem.TYPE_URL);
		sysAdmin_3.setMenuItemLevel(1);
		sysAdmin.addMenuItem(sysAdmin_3);
		
		MenuItem sysAdmin_4 = new MenuItem();
		sysAdmin_4.setMenuItemName("流程管理");
		sysAdmin_4.setMenuItemTarget("#");
		sysAdmin_4.setMenuItemType(MenuItem.TYPE_URL);
		sysAdmin_4.setMenuItemLevel(1);
		sysAdmin.addMenuItem(sysAdmin_4);
		
		MenuItem sysAdmin_5 = new MenuItem();
		sysAdmin_5.setMenuItemName("菜单管理");
		sysAdmin_5.setMenuItemTarget("/sys/menu/toPage/main.action");
		sysAdmin_5.setMenuItemType(MenuItem.TYPE_URL);
		sysAdmin_5.setMenuItemLevel(1);
		sysAdmin.addMenuItem(sysAdmin_5);
		
		MenuItem sysAdmin_6 = new MenuItem();
		sysAdmin_6.setMenuItemName("基础资料维护");
		sysAdmin_6.setMenuItemTarget("/sys/ci/toPage/main.action");
		sysAdmin_6.setMenuItemType(MenuItem.TYPE_URL);
		sysAdmin_6.setMenuItemLevel(1);
		sysAdmin.addMenuItem(sysAdmin_6);
		
		MenuItem attendance_1 = new MenuItem();
		attendance_1.setMenuItemName("考勤查询");
		attendance_1.setMenuItemTarget("#");
		attendance_1.setMenuItemType(MenuItem.TYPE_URL);
		attendance_1.setMenuItemLevel(1);
		attendance.addMenuItem(attendance_1);
		
		MenuItem attendance_2 = new MenuItem();
		attendance_2.setMenuItemName("考勤记录单");
		attendance_2.setMenuItemTarget("#");
		attendance_2.setMenuItemType(MenuItem.TYPE_URL);
		attendance_2.setMenuItemLevel(1);
		attendance.addMenuItem(attendance_2);
		
		MenuItem attendance_3 = new MenuItem();
		attendance_3.setMenuItemName("请假单");
		attendance_3.setMenuItemTarget("#");
		attendance_3.setMenuItemType(MenuItem.TYPE_URL);
		attendance_3.setMenuItemLevel(1);
		attendance.addMenuItem(attendance_3);
		
		MenuItem attendance_4 = new MenuItem();
		attendance_4.setMenuItemName("外出登记单");
		attendance_4.setMenuItemTarget("#");
		attendance_4.setMenuItemType(MenuItem.TYPE_URL);
		attendance_4.setMenuItemLevel(1);
		attendance.addMenuItem(attendance_4);
		
		MenuItem analyseQuery_1 = new MenuItem();
		analyseQuery_1.setMenuItemName("外出情况");
		analyseQuery_1.setMenuItemTarget("#");
		analyseQuery_1.setMenuItemType(MenuItem.TYPE_URL);
		analyseQuery_1.setMenuItemLevel(1);
		analyseQuery.addMenuItem(analyseQuery_1);
		
		MenuItem analyseQuery_2 = new MenuItem();
		analyseQuery_2.setMenuItemName("出勤情况");
		analyseQuery_2.setMenuItemTarget("#");
		analyseQuery_2.setMenuItemType(MenuItem.TYPE_URL);
		analyseQuery_2.setMenuItemLevel(1);
		analyseQuery.addMenuItem(analyseQuery_2);

		MenuItem analyseQuery_3 = new MenuItem();
		analyseQuery_3.setMenuItemName("请假情况");
		analyseQuery_3.setMenuItemTarget("#");
		analyseQuery_3.setMenuItemType(MenuItem.TYPE_URL);
		analyseQuery_3.setMenuItemLevel(1);
		analyseQuery.addMenuItem(analyseQuery_3);
		
		roleDeveloper.addMenuItem(sysAdmin);
		roleDeveloper.addMenuItem(sysAdmin_1);
		roleDeveloper.addMenuItem(sysAdmin_2);
		roleDeveloper.addMenuItem(sysAdmin_3);
		roleDeveloper.addMenuItem(sysAdmin_4);
		roleDeveloper.addMenuItem(sysAdmin_5);
		roleDeveloper.addMenuItem(sysAdmin_6);
		
		roleDeveloper.addMenuItem(attendance);
		roleDeveloper.addMenuItem(attendance_1);
		roleDeveloper.addMenuItem(attendance_2);
		roleDeveloper.addMenuItem(attendance_3);
		roleDeveloper.addMenuItem(attendance_4);
		
		roleDeveloper.addMenuItem(analyseQuery);
		roleDeveloper.addMenuItem(analyseQuery_1);
		roleDeveloper.addMenuItem(analyseQuery_2);
		roleDeveloper.addMenuItem(analyseQuery_3);
		
		roleManager.addMenuItem(attendance);
		roleManager.addMenuItem(attendance_1);
		roleManager.addMenuItem(attendance_2);
		roleManager.addMenuItem(attendance_3);
		roleManager.addMenuItem(attendance_4);
		
		roleManager.addMenuItem(analyseQuery);
		roleManager.addMenuItem(analyseQuery_1);
		roleManager.addMenuItem(analyseQuery_2);
		roleManager.addMenuItem(analyseQuery_3);
		
		roleHR.addMenuItem(sysAdmin);
		roleHR.addMenuItem(sysAdmin_1);
		roleHR.addMenuItem(sysAdmin_2);
		roleHR.addMenuItem(sysAdmin_3);
		roleHR.addMenuItem(sysAdmin_4);
		roleHR.addMenuItem(sysAdmin_5);
		roleHR.addMenuItem(sysAdmin_6);
		
		
	}
}
